package com.wsseieiei.fireballgame.blocks;

import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nonnull;

import static com.wsseieiei.fireballgame.init.BlockEntityInit.OC_BLOCK_ENTITY;

public class Occupyer {
    public static final class Oc extends BaseEntityBlock {
        public Oc(Properties props) {
            super(props);
        }
        @Nonnull
        @Override
        public RenderShape getRenderShape(@Nonnull BlockState state) {
            return RenderShape.MODEL;
        }
        @Override
        public BlockEntity newBlockEntity(@Nonnull BlockPos pos, @Nonnull BlockState state) {
            return new OcEntity(pos, state);
        }
        @Override
        public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, @Nonnull BlockState state, @Nonnull BlockEntityType<T> blockEntityType) {
            return level.isClientSide() ? null : createTickerHelper(blockEntityType, OC_BLOCK_ENTITY.get(), OcEntity::tick);
        }
    }
    public static final class OcEntity extends BlockEntity {
        public OcEntity(BlockEntityType<OcEntity> type, BlockPos worldPosition, BlockState blockState) {
            super(type, worldPosition, blockState);
        }
        public OcEntity(BlockPos worldPosition, BlockState blockState) {
            this(OC_BLOCK_ENTITY.get(), worldPosition, blockState);
        }
        private int count = 0;
        public static void tick(Level level, BlockPos pos, BlockState state, OcEntity entity) {
            if (level != null && !level.isClientSide()) {
                level.removeBlock(new BlockPos(pos.getX(),pos.getY()-1,pos.getZ()),true);
            }
        }
    }
}
